home *** CD-ROM | disk | FTP | other *** search
- /*
- * numbered_cleanup: function
- * This function is used as a fuse to delete objects created by the
- * "numberedObject" class in reponse to calls to its newNumbered
- * method. Whenever that method creates a new object, it sets up a fuse
- * call to this function to delete the object at the end of the turn in
- * which it created the object.
- */
- numbered_cleanup: function( obj )
- {
- delete obj;
- }
-
- /*
- * numberedObject: object
- * This class can be added to a class list for an object to allow it to
- * be used as a generic numbered object. You can create a single object
- * with this class, and then the player can refer to that object with
- * any number. For example, you can create a single "button" object
- * that the player can refer to with "button 100'' or "button 1000''
- * or any other number. If you want to limit the range of acceptable
- * numbers, override the "num_is_valid" method so that it displays
- * an appropriate error message and returns "nil" for invalid numbers.
- * If you want to use a separate object to handle references to the object
- * with a plural ("look at buttons"), override "newNumberedPlural" to
- * return the object to handle these references; by default, the original
- * object is used to handle plurals.
- */
-
- class numberedObject: object
- adjective = '#'
- anyvalue( n ) = { return n; }
- clean_up = { delete self; }
- newNumberedPlural( a, v ) = { return self; }
- newNumbered( a, v, n ) =
- {
- local obj;
-
- if ( n = nil ) return self.newNumberedPlural( a, v );
- if ( not self.num_is_valid( n ) ) return nil;
- obj := new self;
- obj.value := n;
- setfuse( numbered_cleanup, 0, obj );
- return obj;
- }
- num_is_valid( n ) =
- {
- if ( n = 0 )
- {
- "There aren't zero "; self.pluraldesc; " here! ";
- return nil;
- }
- else if ( n > self.maxNum )
- {
- "There aren't that many "; self.pluraldesc; "! ";
- return nil;
- }
- else
- return true;
- }
- dobjGen( a, v, i, p ) =
- {
- if ( self.value = nil )
- {
- "You'll have to be more specific about which one you mean. ";
- exit;
- }
- }
- iobjGen( a, v, d, p ) = { self.dobjGen( a, v, d, p ); }
- maxNum = 10
- ;